package com.sskj.cndragon.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.cndragon.ui.activity.RegisterActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.http.JsonCallBack;


public class RegisterActivityPresenter extends BasePresenter<RegisterActivity> {

    public void register(String mobile, String code, String pwd, String invitationCode) {
        httpService.register(mobile, code, MD5Util.getMd5Value(pwd), invitationCode)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == BaseHttpConfig.OK) {
                            mView.registerSuccess();
                        }
                    }
                });
    }

    public void getCode(String tel, int codeType) {
        httpService.getCode(tel, codeType)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == BaseHttpConfig.OK) {
                            mView.getCodeSuccess();
                        }
                    }
                });
    }

}
